package com.appprogram.baseapppackage.util;


import android.content.Context;

import com.appprogram.baseapppackage.R;
import com.azhon.appupdate.config.UpdateConfiguration;
import com.azhon.appupdate.manager.DownloadManager;
import com.blankj.utilcode.util.AppUtils;


/**
 * BaseAppPackage com.appprogram.baseapppackage.util
 * 2020-01-08 16:05
 */
public class AppUpdateUtil {
    private static AppUpdateUtil sAppUpdateUtil;

    public static AppUpdateUtil getInstance() {
        if (null == sAppUpdateUtil) {
            synchronized (AppUpdateUtil.class) {
                if (null == sAppUpdateUtil) sAppUpdateUtil = new AppUpdateUtil();
            }
        }
        return sAppUpdateUtil;
    }

    public void update(Context pContext, String apkUrl, String title, String updateContent) {
        UpdateConfiguration configuration = new UpdateConfiguration().setForcedUpgrade(true);
        DownloadManager manager = DownloadManager.getInstance(pContext);
        configuration.setEnableLog(true)
                .setJumpInstallPage(true)
                .setJumpInstallPage(true)
                .setShowNotification(true)
                .setShowBgdToast(true)
                .setForcedUpgrade(true);
        manager.setApkName("App.apk")
                .setAuthorities(AppUtils.getAppPackageName())
                .setApkUrl(apkUrl)
                .setShowNewerToast(true)
                .setConfiguration(configuration)
                .setSmallIcon(R.drawable.ic_launcher_web)
                .setApkVersionCode(AppUtils.getAppVersionCode() + 1)
                .setApkVersionName(AppUtils.getAppVersionName())
                .setApkDescription(updateContent)
                .download();
    }
}
